<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
use \Illuminate\Support\Facades\Route;


Route::get('/t1', 'TestController@t1');

Route::get('/', function () {
    $msg = session()->get('msg');
    session()->forget('msg');
    return view('welcome',compact('msg'));
});

Route::middleware('guest')->group(function (){
    //微信公众号登陆
    Route::get('wx/{mall_id}/auth', 'WxController@wxAuthLogin')->name('wx.auth');
    //微信公众号登陆回调
    Route::get('wx/{mall_id}/auth-callback', 'WxController@wxAuthCallback')->name('wx.authCallback');
});

Route::middleware('auth.wx')->group(function (){
    //查看报告
    Route::get('report/{mall_id}/show', 'HomeController@reportDetail')->name('report.detail');
    //历史报告
    Route::get('report/{mall_id}/his', 'HomeController@hisReport')->name('report.his');
    //welcome
    Route::get('/auth/{mall_id}/success', function(){
//        $msg = session()->get('msg');
//        session()->forget('msg');
        $msg = '信息获取成功';
        return view('welcome',compact('msg'));
    })->name('auth.success');
});


//Route::get('report/{mall_id}/his', 'HomeController@hisReport')->name('report.his');

//Route::get('/wx', 'WxController@wxAuthCallback');
//微信事件通知
Route::any('/wx/{mall_id}/event-notify', 'WxNotifyController@notify');

Route::prefix('manage')->group(function () {
    //后台管理页面
    Route::middleware('guest:admin')->group(function (){
        //pc登陆
        Route::get('/login', 'WxController@wxQrcodeLogin')->name('manage.wxlogin');
        //检查是否登陆成功
        Route::any('/check-login', 'WxController@checkWxQrcodeLogin')->name('manage.checkLogin');
        //登陆成功跳转
        Route::get('/login-success', 'WxController@wxQrcodeLoginSuccess');
    });

    //后台管理页面
    Route::middleware('auth:admin')->group(function (){
        Route::any('/reports', 'ManageController@reportList')->name('reports');
        Route::post('/report/sync', 'ManageController@reportSync')->name('report.sync');
        Route::any('/users', 'ManageController@userList')->name('users');
        Route::any('/staffs', 'ManageController@staffList')->name('staffs')->middleware('can:superAdmin');
        Route::any('/setting', 'ManageController@reportSetting')->name('setting');
        Route::any('/edit_staff', 'ManageController@editStaff');

        //退出
        Route::get('/logout', 'ManageController@logout');
    });
});

